import matplotlib.pyplot as plt

conf = []
real = []

def read_conf():
    path = "置信度.txt"
    file = open(path,"r")
    for line in file:
        conf.append(line[20:21])
        real.append(line[26:27])

def plt_conf(length,true_list,col,str=None):
    plt.plot(range(length), true_list, color=col)
    plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
    plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号
    plt.title(str+"加入训练集的无标签样本数与正确率的变化曲线")
    plt.xlabel("加入训练集的无标签样本数")
    plt.ylabel("伪标签的正确率")
    plt.show()

def drew():
    cnt = 0
    cnt_thousand=0
    true_list = []
    thousand_list = []
    for i in range(len(conf)):
        if conf[i] == real[i]:
            if (i+1)%1000 == 0:
                thousand_list.append(cnt_thousand / 1000)
                cnt_thousand = 0
                plt_conf(1000,thousand_list,"blue","第"+str((i+1)//1000)+"个1000样本集")
            cnt = cnt + 1
            cnt_thousand = cnt_thousand + 1
        thousand_list.append(cnt_thousand/((i+1)%1000+1))
        if (i+1)%1000 == 0:
            thousand_list = []
        true_list.append(cnt/(i+1))
    plt_conf(len(conf),true_list,"red","")
if __name__ == "__main__":
    read_conf()
    drew()